package com.gqz.controller.system;


import com.gqz.domain.BlogArticleType;
import com.gqz.dto.ArticleTypeDto;
import com.gqz.query.BaseQuery;
import com.gqz.service.IBlogArticleTypeService;
import com.gqz.utils.JsonResult;
import com.gqz.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/sys/blog/articleType")
public class SysBlogArticleTypeController {

    @Autowired
    private IBlogArticleTypeService blogArticleTypeService;

    @GetMapping({"/{pageIndex}/{pageSize}/{keyword}", "/{pageIndex}/{pageSize}"})
    public JsonResult getAllArticleType(BaseQuery query) {
        PageList<BlogArticleType> result = blogArticleTypeService.getAllArticleType(query);
        return JsonResult.ok(result);
    }

    @GetMapping
    public JsonResult getAllArticleType() {
        List<ArticleTypeDto> result = blogArticleTypeService.getAllArticleType();
        return JsonResult.ok(result);
    }

    @PostMapping
    public JsonResult add(@RequestBody BlogArticleType articleType, HttpServletRequest request) {
        boolean result = blogArticleTypeService.insertArticleType(articleType, request);
        return JsonResult.toAjax(result);
    }

    @DeleteMapping
    public JsonResult remove(@RequestBody Long[] ids) {
        boolean result = blogArticleTypeService.batchDeleteArticleType(ids);
        return JsonResult.toAjax(result);
    }

    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable Long id) {
        boolean result = blogArticleTypeService.deleteArticleType(id);
        return JsonResult.toAjax(result);
    }

    @PutMapping
    public JsonResult edit(@RequestBody BlogArticleType articleType, HttpServletRequest request) {
        boolean result = blogArticleTypeService.updateArticleType(articleType, request);
        return JsonResult.toAjax(result);
    }
}
